package pkg.hicph.org;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class EatPlaceScreen extends Activity implements OnClickListener  {
    
    public TextView eatPlaceInfo, eatPlaceTitle;
    public Button actionButton, cancelButton;
    
    public String modifiersDescription = "";


	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  
	  requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(
      WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
	  
	  setContentView(R.layout.eatplacescreen);
	  
	  registerViews();
	  setupOnClickListeners();
	  
	  if(Utils.gamePhase == Utils.PAUSE_EAT_MODE){
		  eatPlaceTitle.setText("You just entered \n" + Utils.activePlace.name + " to buy food and eat.");
		  eatPlaceInfo.setText(Utils.activePlace.desc);
		  actionButton.setText("Buy food and eat");
	  }
	  else {
		  eatPlaceTitle.setText("You just found \n" + Utils.activePlace.name + ".");
		  eatPlaceInfo.setText(Utils.activePlace.desc); 
		  actionButton.setText("Go get money");
	  }
	  
//	  this.setTitle("You just found this place:");
	  
	  
	}
	
	
//	private void loadPrefs() {
//		
//		String actionName;
//		
//    	preferences  = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
//    	
//    	actionName = preferences.getString("nextActionName", "");
//    	
//    	Log.d("DIALOG","loaded: " + actionName);
//    	
//    	actionToPerform = Utils.nextAction;
//    	
//    	actionToPerform = Utils.getActionByName(actionName);
//    	Log.d("DIALOG","action: " + actionToPerform.name);
//        
//	}
	
	
	private void registerViews() {
			
		 actionButton = (Button) this.findViewById(R.id.eat_place_action_button);
		 cancelButton = (Button) this.findViewById(R.id.eat_place_cancel_button);
		 eatPlaceInfo = (TextView) this.findViewById(R.id.eat_place_dialog_info);
		 eatPlaceTitle = (TextView) this.findViewById(R.id.eat_place_dialog_title);
	}

	
	public void setupOnClickListeners() {
        
		actionButton.setOnClickListener(this);
		cancelButton.setOnClickListener(this);

    }
    
	
    public void onClick(View V) {
    	
    	switch(V.getId()) {
    	
    	case R.id.eat_place_action_button:
    		
    		// COMPUTES ACTION
    		
    		
    		Log.d("CLICKED", Utils.gamePhase + "");
    		
    		if(Utils.gamePhase == Utils.PAUSE_EAT_MODE){
    			
    			Utils.gamePhase = Utils.START_SLEEP_MODE;
    			
    			if(Utils.activePlace.action.equalsIgnoreCase("eat healthy food")){
    				
    				if(!Utils.getEventByName("Being Healthier").achieved){
    					Utils.getEventByName("Being Healthier").achieved = true;
    					Utils.achievedInSession++;
    				}
    				
    			}
    			
    			Utils.player.dayStory += "You bought some food at "+ Utils.activePlace.name +" and ate it. After eating, you started to feel very tired and decided to find a place to sleep.";
    			
    			Intent sleepIntent = new Intent(this, SleepScreen.class);
        		this.startActivity(sleepIntent);
    			
    		}
    		else {
    		  Utils.gamePhase = Utils.START_MONEY_PROBLEM;
    		  
    		  Utils.player.dayStory += " After going to "+ Utils.activePlace.name +", you had to go get enough money to eat.";
    		  
    		  
    		}
    		
    		// CLOSES THE DIALOG
    		this.finish();
    		
    		break;
    		
    	case R.id.eat_place_cancel_button:
    		
    		
    		if(Utils.gamePhase == Utils.PAUSE_EAT_MODE){

	  		}
	  		else {
	  			Utils.gamePhase = Utils.PLAY_HUNGRY_MODE;
	  		 }
    		// CANCELS ACTION
    		
    		
    		// CLOSES THE DIALOG
    		this.finish();
    		
    		break;
    		
    	}

    }


}


